package com.itsm.xkitsm.liferoot.life;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.itsm.xkitsm.liferoot.MainAct;
import com.itsm.xkitsm.liferoot.R;
import com.itsm.xkitsm.liferoot.adapter.Info_lvdetail;
import com.itsm.xkitsm.liferoot.adapter.MybaseAdapter_lvdetail;

public class PhoneActivity extends Activity implements OnClickListener {
	private TextView tv_phone_express, tv_phone_number, tv_phone_bank;
	private ListView lv_detail;
	private String[] strarr_name_express, strarr_name_phone, strarr_name_bank;
	private String[] strarr_number_express, strarr_number_phone,
			strarr_number_bank;
	private List<Info_lvdetail> data_express, data_number, data_bank, data;
	private MybaseAdapter_lvdetail adapter_lvdetail;
	private ImageView img_phone;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.phone);
		bind();
		lv_detail.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
						+ data.get(arg2).getNumber()));
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(intent);
			}
		});
		onClick(tv_phone_express);
	}

	private void bind() {
		img_phone = (ImageView) findViewById(R.id.img_phone);
		img_phone.setOnClickListener(this);

		tv_phone_express = (TextView) findViewById(R.id.tv_phone_express);
		tv_phone_number = (TextView) findViewById(R.id.tv_phone);
		tv_phone_bank = (TextView) findViewById(R.id.tv_phone_bank);
		lv_detail = (ListView) findViewById(R.id.lv_detail);
		tv_phone_express.setOnClickListener(this);
		tv_phone_number.setOnClickListener(this);
		tv_phone_bank.setOnClickListener(this);
		tv_phone_express.setText("快递" + "\n" + "服务");
		tv_phone_number.setText("常用" + "\n" + "电话");
		tv_phone_bank.setText("银证" + "\n" + "保险");

		Resources res = getResources();
		strarr_name_express = res.getStringArray(R.array.phone_name_express);
		strarr_name_phone = res.getStringArray(R.array.phone_name_life);
		strarr_name_bank = res.getStringArray(R.array.phone_name_bank);
		strarr_number_express = res
				.getStringArray(R.array.phone_number_express);
		strarr_number_phone = res.getStringArray(R.array.phone_number_life);
		strarr_number_bank = res.getStringArray(R.array.phone_number_bank);
		data_express = getData(strarr_name_express, strarr_number_express);
		data_number = getData(strarr_name_phone, strarr_number_phone);
		data_bank = getData(strarr_name_bank, strarr_number_bank);

	}

	public List<Info_lvdetail> getData(String[] name, String[] number) {
		List<Info_lvdetail> temp = new ArrayList<Info_lvdetail>();
		for (int i = 0; i < name.length; i++) {
			temp.add(new Info_lvdetail(name[i], number[i]));
		}
		return temp;
	}

	@Override
	public void onClick(View v) {
		tv_phone_express.setBackgroundColor(Color.WHITE);
		tv_phone_number.setBackgroundColor(Color.WHITE);
		tv_phone_bank.setBackgroundColor(Color.WHITE);
		data = null;
		switch (v.getId()) {

		case R.id.img_phone:
			Intent it = new Intent(PhoneActivity.this,
					MainAct.class);
			startActivity(it);
			break;
		case R.id.tv_phone_express: {
			data = data_express;
			tv_phone_express.setBackgroundColor(Color.YELLOW);
		}
			break;

		case R.id.tv_phone: {
			data = data_number;
			tv_phone_number.setBackgroundColor(Color.YELLOW);
		}
			break;

		case R.id.tv_phone_bank: {
			data = data_bank;
			tv_phone_bank.setBackgroundColor(Color.YELLOW);
		}
			break;
		}
		if (null != data) {
			adapter_lvdetail = new MybaseAdapter_lvdetail(this, data);
			lv_detail.setAdapter(adapter_lvdetail);
		}

	}
}
